package com.hepinghospital.user.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.hepinghospital.user.R;
import com.rest.response.PrescriptionResponse;

import org.jetbrains.annotations.NotNull;

import java.util.List;


/**
 *
 * @author HP
 * @date 2020/3/2
 */

public class MedicineAdapter extends RecyclerView.Adapter<MedicineAdapter.Holder> {

    private Context context;
    private List<PrescriptionResponse.Prescription> list;

    public MedicineAdapter(Context context, List<PrescriptionResponse.Prescription> list) {
        this.context = context;
        this.list = list;
    }


    @NotNull
    @Override
    public Holder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        Holder myHolder;
        myHolder = new Holder(LayoutInflater.from(context).inflate(R.layout.item_medicine, parent, false));
        return myHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.itemView.setOnClickListener(v -> {
//                Bundle bundle = new Bundle();
//                bundle.putSerializable("obj", list.get(position));
//                startActivity(CheckActivity.class, bundle);
        });
        holder.tv_medicine_name.setText(list.get(position).name);
        holder.tv_medicine_num.setText(list.get(position).drugUsing + "  " + list.get(position).drugDose + "/次  " + list.get(position).drugChannel);
        holder.tv_medicine_price.setText(list.get(position).expense + "*" + list.get(position).drugNumber + "=" + list.get(position).totalExpense + "元");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class Holder extends RecyclerView.ViewHolder {

        TextView tv_medicine_name, tv_medicine_num, tv_medicine_price;

        Holder(View itemView) {
            super(itemView);
            tv_medicine_name = itemView.findViewById(R.id.tv_medicine_name);
            tv_medicine_num = itemView.findViewById(R.id.tv_medicine_num);
            tv_medicine_price = itemView.findViewById(R.id.tv_medicine_price);
        }
    }
}
